﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Cosmetic;
using Cosmetic.Logic;

public partial class Management_Admin_ChangePassword : PageBase2
{
	private UserManager m_UserManager	= new UserManager();
    private RoleManager m_RoleManager = new RoleManager();
	protected void Page_Load(object sender, EventArgs e)
	{
        if (this.SignInUser1 == null)
        {
            Session.Remove("SignInUser1");
            this.ClientScript.RegisterStartupScript(this.GetType(), this.Title, "alert('请先登录权限!');window.top.location.href='/Management/indexs.aspx';", true);
            return;
        }
        if (!IsPostBack)
        {
            Cosmetic.DataEntity.User theUser = this.SignInUser1;
            if (!this.m_RoleManager.CheckUserRole(theUser, RoleManager.ERole.Admin))
            {
                Session.Remove("SignInUser1");
                this.ClientScript.RegisterStartupScript(this.GetType(), this.Title, "alert('你没有管理员权限!');window.top.location.href='/Management/indexs.aspx';", true);
                return;
            }
        }
	}

	protected void btnSubmit_Click(object sender, EventArgs e)
	{
		if (!this.SignInUser1.Password.Equals(this.txtOldPassword.Text))
		{
			WebGeneric.WebMessageBox("原密码不正确!", this.Page);
			return;
		}

		this.SignInUser1.Password	= this.txtPassword.Text;
		this.m_UserManager.Update();
		WebGeneric.WebMessageBox("密码修改成功，请重新登录!", this.Page);
		this.SignOut();
		//this.Response.Redirect(this.Request.Url.PathAndQuery);
	}
}
